

class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None
def InsertList(head,m):
    while head.next!=None:
        head=head.next
    new_node=ListNode(m)
    new_node.next=None
    head.next=new_node
def printList(head):
    while head!=None:
        print(head.val,end='')
        head=head.next
class Solution:
    def reversePrint(self, head: ListNode) :
        ans=[]
        while head!=None:
            ans.append(head.val)
            head=head.next

        print(ans)
        ans.reverse()
        print(ans)

if __name__ == '__main__':
    h = ListNode(20)
    h.next = None
    for i in range(10):
        InsertList(h,i)
    s=Solution()
    s.reversePrint(h)

